package com.java.module.fire.controller.admin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.fire.domain.Apply;
import com.java.module.fire.service.IApplyService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 报名Controller
 * 
 * @author Administrator
 * @date 2025-02-10
 */
@RestController("AdminApplyController")
@RequestMapping("/fire/apply")
public class ApplyController {
    @Autowired
    private IApplyService applyService;

    /**
     * 查询报名列表
     */
    @PreAuthorize("@ss.hasPermi('fire:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(Apply apply) {
        WebKit.startPage();
        List<Apply> list = applyService.selectApplyList(apply);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出报名列表
     */
    @PreAuthorize("@ss.hasPermi('fire:apply:export')")
    @Log(title = "报名", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Apply apply) {
        List<Apply> list = applyService.selectApplyList(apply);
        ExcelUtil<Apply> util = new ExcelUtil<Apply>(Apply.class);
        return util.exportExcel(list, "apply");
    }

    /**
     * 获取报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:apply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId) {
        return AjaxResult.success(applyService.selectApplyById(applyId));
    }

    /**
     * 新增报名
     */
    @PreAuthorize("@ss.hasPermi('fire:apply:add')")
    @Log(title = "报名", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Apply apply) {
        return WebKit.toAjax(applyService.insertApply(apply));
    }

    /**
     * 修改报名
     */
    @PreAuthorize("@ss.hasPermi('fire:apply:edit')")
    @Log(title = "报名", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Apply apply) {
        return WebKit.toAjax(applyService.updateApply(apply));
    }

    /**
     * 删除报名
     */
    @PreAuthorize("@ss.hasPermi('fire:apply:remove')")
    @Log(title = "报名", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds) {
        return WebKit.toAjax(applyService.deleteApplyByIds(applyIds));
    }
}
